package com.bsi.conf;

import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.FilterType;
import org.springframework.stereotype.Repository;
import org.springframework.stereotype.Service;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.ViewResolverRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.web.servlet.view.InternalResourceViewResolver;


/**
 * @ClassName SpringMvcInitConfig
 * @Author LiuSong
 * @Date 2020/8/11 9:54
 * @Version 1.0
 * @Description
 */
@Configuration
@ComponentScan(basePackages = "com.bsi", excludeFilters = {@ComponentScan.Filter
        (classes = {Service.class, Repository.class}, type = FilterType.ANNOTATION)})
@EnableWebMvc
public class SpringMvcInitConfig implements WebMvcConfigurer {

    /**
     * 配置spring的视图解析器
     *
     * @param registry
     */
    @Override
    public void configureViewResolvers(ViewResolverRegistry registry) {
        InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();
        viewResolver.setPrefix("/WEB-INF/views");
        viewResolver.setSuffix(".jsp");
        registry.viewResolver(viewResolver);
    }


    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        registry.addViewController("/").setViewName("redirect:/login");
    }
}
